package com.ai.springai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @Author: suren@517na.com
 * @CreateTime: 2025-06-01
 * @Description: Spring AI Controller
 */

@RestController
@RequestMapping("/spring/ai")
public class SpringAiController {

    @Autowired
    private ChatClient ollamaChatClient;


    @GetMapping("/chat/ollama")
    public String ollamaChat(@RequestParam(defaultValue = "你是谁") String message) {
        return ollamaChatClient.prompt().user(message).call().content();
    }

    @GetMapping(value = "/stream/chat/ollama", produces = "text/stream;charset=UTF-8")
    public Flux<String> ollamaStreamChat(@RequestParam(defaultValue = "你是谁") String message) {
        return ollamaChatClient.prompt().user(message).stream().content();
    }
}
